# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=cve-api
pkgver=170.8e9c247
pkgrel=6
groups=('blackarch' 'blackarch-misc')
pkgdesc='Unofficial api for cve.mitre.org.'
arch=('any')
license=('custom:unknown')
makedepends=('git')
depends=('ruby' 'ruby-bundler' 'libxslt' 'libxml2')
url='https://github.com/Beyarz/Cve-api'
source=("$pkgname::git+https://github.com/Beyarz/Cve-api.git"
        'Gemfile.patch')
sha512sums=('SKIP'
            '4fd827e3e1ee0d4e8bcb90c68bdcd0aaed47d9237e2d78f4415d86196a2a14a947fa0a39dcd19280d8c8403222620dba30cc9922f1a585c14c3fb86e23c25742')
install="$pkgname.install"

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

prepare() {
  patch -p1 < Gemfile.patch
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname" *.md

  cp --no-preserve=ownership -a * "$pkgdir/usr/share/$pkgname/"

  chmod +x "$pkgdir/usr/share/$pkgname/rest.rb"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec bundle exec ruby ./rest.rb "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

